<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for service\MAService.ts</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">all files</a> / <a href="index.html">service/</a> MAService.ts
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">97.37% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>37/38</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">85% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>17/20</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">100% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>4/4</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">97.22% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>35/36</span>
      </div>
    </div>
  </div>
  <div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">42×</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-yes">61×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-yes">105×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">21×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { Injectable } from '@angular/core';
&nbsp;
import { QuoteBasic } from 'service/QuoteBasic';
import { IMAService } from 'interface/IMAService';
&nbsp;
@Injectable()
export class MAService implements IMAService {
&nbsp;
  connection;
&nbsp;
  constructor() {
&nbsp;
  }
&nbsp;
  compute(quote:QuoteBasic, <span class="missing-if-branch" title="if path not taken" >I</span>day:number = 5):Array&lt;any&gt;{
    const maList = [];
    const count = quote.close.length;
&nbsp;
    if(day &gt; 0) {
      for(let i=0; i&lt;count; i++) {
        if(i &lt; day) {
          let sum = 0;
          for(let j=0; j&lt;=i; j++) {
            sum+=quote.close[j];
          }
          maList.push(parseFloat((sum/(i+1)).toFixed(4)));
          continue;
        }
        let sum = 0;
        for(let j=0; j&lt;day; j++) {
          sum+=quote.close[i-j];
        }
        maList.push(parseFloat((sum/day).toFixed(4)));
      }
    }
&nbsp;
    return maList;
  }
&nbsp;
  update(quote:QuoteBasic, day:number, oldList:Array&lt;any&gt;) :Array&lt;any&gt; {
&nbsp;
    const originCount = quote.close.length;
    const oldCount = oldList.length;
    const times = quote.time;
&nbsp;
    if(originCount &gt; 0 &amp;&amp; day &gt; 0) {
&nbsp;
      if(oldCount === 0) {
        return this.compute(quote,day);
      }
&nbsp;
      const start = (originCount - day) &lt; 0 ? 0 : (originCount - day);
      const end = (originCount - 1) &lt; 0 ? <span class="branch-0 cbranch-no" title="branch not covered" >0 </span>: (originCount - 1);
&nbsp;
      <span class="missing-if-branch" title="if path not taken" >I</span>if (start &gt; end) {
<span class="cstat-no" title="statement not covered" >        return oldList;</span>
      }
&nbsp;
      let sum = 0;
      for(let i = start; i &lt;= end; i++) {
        sum+=quote.close[i];
      }
&nbsp;
      if (oldCount &lt; originCount) {
        oldList.push(parseFloat((sum/(end-start+1)).toFixed(4)));
      } else {
        oldList[oldList.length -1] = parseFloat((sum/(end-start+1)).toFixed(4));
      }
    }
&nbsp;
    return oldList;
  }
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Jul 24 2017 16:45:57 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
